package com.junko.core.tool;

import eu.bitwalker.useragentutils.DeviceType;
import eu.bitwalker.useragentutils.UserAgent;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Properties;

/**
 * 系统工具类
 *
 * @author junko
 * @date 2016/11/11
 */
public class ToolSystem {

    /**
     * 是否是线上环境
     */
    public static boolean isOnline(){
        System.out.println("服务器ip = "+ToolWeb.getServerIp());
        if(StringUtils.equals(ToolWeb.getServerIp(),"101.132.146.123")){
            System.out.println("--------------------is online --------------------");
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    /**
     * 是PC
     *
     * @param request
     * @return
     */
    public static boolean isPc(HttpServletRequest request) {
        return StringUtils.equals(UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getOperatingSystem().getDeviceType().getName(), DeviceType.COMPUTER.getName());
    }

    /**
     * 是手机
     *
     * @param request
     * @return
     */
    public static boolean isMobile(HttpServletRequest request) {
        return StringUtils.equals(UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getOperatingSystem().getDeviceType().getName(), DeviceType.MOBILE.getName());
    }

    /**
     * 是windows系统
     *
     * @return
     */
    public static boolean isWindows() {
        Properties prop = System.getProperties();
        String os = prop.getProperty("os.name");
        return StringUtils.startsWithIgnoreCase(os, "win");
    }
}